package edu.ujf.sharepas.rcp;



import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;

import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.resources.IFile;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.GroupMarker;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.StatusLineContributionItem;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.IViewSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.navigator.CommonNavigator;
import org.eclipse.ui.part.ViewPart;
import edu.ujf.sharepas.impl.Category;
import edu.ujf.sharepas.impl.Chat;
import edu.ujf.sharepas.impl.Constante;
import edu.ujf.sharepas.impl.Library;
import edu.ujf.sharepas.impl.ShareFile;
import edu.ujf.sharepas.impl.User;
import edu.ujf.sharepas.rmi.Client;
import edu.ujf.sharepas.rmi.Serveur;

public class NavigationView extends CommonNavigator implements Observer {
	
	public static final String ID = "edu.ujf.sharepas.navigator.view";
	protected TreeViewer treeViewer;
	private Serveur serveur ;  //  @jve:decl-index=0:
	private Client client ;  //  @jve:decl-index=0:
	protected Library root;
	private User user;
	
	/**
	 * The constructor.
	 */
	public NavigationView() {
	}

	/*
	 * @see IWorkbenchPart#createPartControl(Composite)
	 */
	public void createPartControl(Composite parent) {
		super.createPartControl(parent);
		getCommonViewer().setInput(getInitalInput());
	}
	
	 public void updateStatusBar(String message){
         IStatusLineManager statusLine = this.getViewSite().getActionBars().getStatusLineManager();
         StatusLineContributionItem toto =  new StatusLineContributionItem("Notif");
         toto.setText(message);
         statusLine.remove("Notif");
         statusLine.appendToGroup("Notifications",toto);
	 }


	public Object getInitalInput() {

		/*user.getUserLib().addCategory(Constante.CategoryType.VIDEO.toInt()) ;
		user.getUserLib().addCategory(Constante.CategoryType.AUDIO.toInt());
		user.getUserLib().addCategory(Constante.CategoryType.PHOTO.toInt());
		user.getUserLib().addCategory(Constante.CategoryType.DOC.toInt());*/
		List<User> result = new ArrayList<User>();
	
		result.add(user);
		
		for(User u : user.getFriends())
			result.add(u);
		
		return result;
	}
	
	@Override
	public void init(IViewSite site) throws PartInitException {
		super.init(site);
		client = Application.c ;
		try {
			user = client.getUser() ;
			user.addObserver(this);
		} catch (RemoteException e) {
			e.printStackTrace();
		}
	}

	/*
	 * @see IWorkbenchPart#setFocus()
	 */
	public void setFocus() {}
	
	public void setServeur(Serveur s) {
		this.serveur = s;
		
	}

	@Override
	public void update(final Observable arg0, final Object arg1) {
		Display.getDefault().asyncExec(new Runnable(){
			@Override
			public void run() {
				getCommonViewer().refresh((User)arg0);
			}
		});
	}
}